package com.connection.second.wallpaper.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.connection.second.common.annotation.Anonymous;
import com.connection.second.wallpaper.domain.vo.PaperAlbumVo;
import com.connection.second.wallpaper.domain.vo.PaperWallVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.connection.second.common.annotation.Log;
import com.connection.second.common.core.controller.BaseController;
import com.connection.second.common.core.domain.AjaxResult;
import com.connection.second.common.enums.BusinessType;
import com.connection.second.wallpaper.domain.entity.PaperUserCollection;
import com.connection.second.wallpaper.service.IPaperUserCollectionService;
import com.connection.second.common.utils.poi.ExcelUtil;
import com.connection.second.common.core.page.TableDataInfo;

/**
 * 用户收藏Controller
 * 
 * @author FL
 * @date 2024-11-15
 */
@Api(tags = "用户收藏")
@RestController
@RequestMapping("/wallpaper/collection")
public class PaperUserCollectionController extends BaseController
{
    @Autowired
    private IPaperUserCollectionService paperUserCollectionService;


    /**
     * 查询用户收藏列表
     */
    @ApiOperation(value = "查询用户收藏列表")
    @PreAuthorize("@ss.hasRole('user')")
    @GetMapping("/list")
    public AjaxResult list(PaperUserCollection paperUserCollection)
    {
        startPage();
        if (paperUserCollection.getUserId() == null) {
            return error("用户id不能为空");
        }
        if (paperUserCollection.getType() == 1) {
            List<PaperWallVo> list = paperUserCollectionService.selectPaperWallList(paperUserCollection);
            return success(list);
        }
        return error("类型错误");
    }

    /**
     * 判断是否收藏
     */
    @ApiOperation(value = "判断是否收藏")
    @PreAuthorize("@ss.hasRole('user')")
    @GetMapping("/isCollection")
    public AjaxResult isCollection(PaperUserCollection paperUserCollection)
    {
        if (paperUserCollection.getUserId() == null) {
            return error("用户id不能为空");
        }
        if (paperUserCollection.getType() == 1) {
            int status = paperUserCollectionService.selectPaperUserCollectionList(paperUserCollection).get(0).getStatus();
            if (status == 1) {
                return success(true);
            } else {
                return success(false);
            }
        }
        return error("类型错误");
    }



    /**
     * 修改用户收藏
     */
    @ApiOperation(value = "新增用户收藏")
    @PreAuthorize("@ss.hasRole('user')")
    @Log(title = "用户收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperUserCollection paperUserCollection)
    {
        return paperUserCollectionService.userCollection(paperUserCollection);
    }


    /**
     * 删除用户收藏
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:collection:remove')")
    @Log(title = "用户收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paperUserCollectionService.deletePaperUserCollectionByIds(ids));
    }
}
